{extend name="public:base" /}
{block name="content"}	

<div class="page-header">	
<h1>
	{$breadcrumb1}
	<small>
		<i class="ace-icon fa fa-angle-double-right"></i>
		{$breadcrumb2}
	</small>
	<small>
		<i class="ace-icon fa fa-angle-double-right"></i>
		{$crumbs}
	</small>			
<button name="send"  type="submit" style="float:right;"  class="btn button btn-sm btn-primary">提交</button>
</h1>

</div>
<div class="row">
	<div class="col-xs-12">	
		
		<div class="form-horizontal">
			{if condition="$Request.param.id"}
			<input name="id" type="hidden" value="{$Request.param.id}" />
			{/if}
			
		
			
			<div class="form-group">
				<label class="col-sm-2 control-label"> * 属性名称 </label>
			<div class="col-sm-10">
				<div class="clearfix">
					<input name="name" id="name" class="col-xs-10 col-sm-5"  value="{$attribute.name|default=''}" type="text">
				</div>
			</div>			 
			</div>

			
			<table id="attribute-value" class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<td class="text-left required">属性值：</td>						
						<td class="text-left">  排序：</td>
						<td></td>
					</tr>
				</thead>
				<tbody>
					<?php $attribute_value_row = 1; ?>
					<?php if(isset($attribute_values)){ ?>
					<?php foreach ($attribute_values as $attribute_value) { ?>
		              <tr id="attribute-value-row<?php echo $attribute_value_row; ?>">
		                <td class="text-left">
		                	<input type="text" name="attribute_value[<?php echo $attribute_value_row; ?>][name]" value="<?php echo $attribute_value['value_name']; ?>"  class="form-control"  />
		                </td>
		               
		                <td class="text-right"><input type="text" name="attribute_value[<?php echo $attribute_value_row; ?>][sort_order]" value="<?php echo $attribute_value['value_sort_order']; ?>" class="form-control" /></td>
		                <td class="text-left"><button type="button" onclick="$('#attribute-value-row<?php echo $attribute_value_row; ?>').remove();" data-toggle="tooltip"  class="btn btn-danger"><i class="fa fa-trash"></i></button></td>
		              </tr>
		              <?php $attribute_value_row++; ?>
		              <?php } ?>
		              <?php } ?>
				</tbody>
			</table>
			<div>
				<a class="add_image btn btn-primary " onclick="addAttributeValue();">添加属性值</a>
			</div>
			
		</div>
	</div>
</div>
{/block}
{block name="javascript"}

<script>
var attribute_value_row = '<?php echo $attribute_value_row; ?>';

function addAttributeValue() {
	html  = '<tr id="attribute-value-row' + attribute_value_row + '">';		
	html += '<td class="text-left">';
	html += '<div><input type="text" name="attribute_value[' + attribute_value_row + '][name]" value=""  class="form-control" />';
    html += '</div>';	
	html += '</td>';
	html += '  <td class="text-right"><input type="text" name="attribute_value[' + attribute_value_row + '][sort_order]" value="' + attribute_value_row + '" class="form-control" /></td>';
	html += '  <td class="text-left"><button type="button" onclick="$(\'#attribute-value-row' + attribute_value_row + '\').remove();" data-toggle="tooltip"  class="btn btn-danger"><i class="fa fa-trash"></i></button></td>';
	html += '</tr>';	
	
	$('#attribute-value tbody').append(html);
	
	attribute_value_row++;
}


var back_index="{:url('attribute/index')}";

$('.button').click(function(){
	$.post(
		'{$action}',
		$('input[type=\'text\'],select,input[type=\'hidden\']'),
		function(d){
			art_dialog(d,back_index);
		}
	);
});

</script>							
{/block}